const install = (Vue, vm) => {
	Vue.prototype.$u.http.setConfig({
		//baseUrl: 'https://ynlk.smart-build.cn',
		baseUrl: 'https://v2.smart-build.cn',
		loadingText: '努力加载中~',
		loadingTime: 60*1000,
		originalData:true,
		header:{}
	});
	// 请求拦截部分
	Vue.prototype.$u.http.interceptor.request = (config) => {
		//模块id
		config.header['TENANT-ID'] = 9
		//项目id
		config.header['Project-Id'] = vm.vuex_project ? JSON.parse(vm.vuex_project).deptId : 1
		if(vm.vuex_userInfo){
			let user = JSON.parse(vm.vuex_userInfo)
			config.header.Authorization = 'Bearer ' + user.access_token;
		} 
		if(config.url.indexOf('/auth/oauth/token')>=0){
			config.header['content-type'] = 'application/x-www-form-urlencoded'
			config.header.isToken = 'false';
			config.header.Authorization = "Basic cGlnOnBpZw==";
		}
		return config;
	}
	// 响应拦截
	Vue.prototype.$u.http.interceptor.response = (result) => {
		//请求成功
		if(result.statusCode == 200){
			return result.data
		}
		if(result.statusCode == 401){
			vm.$u.toast('用户信息已失效，请重新登录');
			vm.$u.route('/pages/login')
			return false;
		}
	}
}

export default {
	install
}